import BasePanel from "./BasePanel";
import CommonConstant from "../../constant/CommonConstant";
import LanguageManager from "../../constant/LanguageManager";
import EnumData from "../../Enum/EnumData";
import { utils } from "../../utils/CommonUtil";
import HintUi from "../UI/GamePanel/HintUi";

export default class HintPanel extends BasePanel {
    constructor(id: number) {
        super();
        this.m_nameID = id;

        this.InitFui();
        this.mowner = this.m_fui.displayObject;
        this.mowner.alpha = 0;
        Laya.Tween.to(this.mowner, { alpha: 1 }, 500);
        // this.InitData();
    }

    private InitFui() {
        this.m_fui = window.gameFacade.ResourceMng.
        getMainCom(CommonConstant._fuiHintPanelPath.Package, "HintPanel", "HintPanel");

        let bg = this.m_fui.getChild("bg").asImage;

        let ratio = Laya.Browser.clientWidth/Laya.stage.width; ///  xxx/750 算出相对比例
        let h = Laya.Browser.clientHeight/ratio;

        bg.height = h;
        
        let titleText = this.m_fui.getChild("hintText").asLabel;
        titleText.text =  window.gameFacade.ConfigMng.GetLanguageByKey(LanguageManager.HINT);

        let backBtn = this.m_fui.getChild("backBtn").asButton;
        backBtn.onClick(this, this.OnBackbtnClick)

        let HintList = this.m_fui.getChild("HintList").asList;
        HintList.removeChildrenToPool();
        HintList.foldInvisibleItems = true;

        let id =  window.gameFacade.LevelMng.GetCurLevelData().id;
        let hitDatas = window.gameFacade.ConfigMng.GetHintDataByLevel(id);

        for (let index = 0; index < hitDatas.length; index++) {
            const hintData = hitDatas[index];
            let HintUiCom: fairygui.GComponent = HintList.addItemFromPool().asCom;
            /** 根据获得的道具 生成对应的道具ui*/
            let hintUI: HintUi = utils.CommonUtils.CustomAddComponent(HintUiCom.displayObject, HintUi) as HintUi;
            hintUI.SetData(HintUiCom, hintData, this,index);
        }
        super.Show();
    }

    private OnBackbtnClick(){
        window.gameFacade.SceneMng.close(EnumData.EnumPanelType.HintPanel);
    }
}